package com.nari.ies.ne.nw.server.activator;

import com.nari.ies.ne.nw.server.service.fileScore.IPlantScoreService;
import com.nari.ies.ne.nw.server.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Slf4j
public class FileScoreByYearActivator {

    @Autowired
    private IPlantScoreService plantScoreService;
    @Scheduled(cron = "0 10 2 * * ?")
    //@Scheduled(cron = "0 0/30 * * * ?")
    public void TaskFileScore() {
        log.info("-----文件算分开始-----" + new Date());

        Date dateTime = DateUtil.getToday();
        //Date dateTime = new Date("2023/09/06");

        // 查询当天是否为一月一日
        Boolean firstDayOfYear = DateUtil.isFirstDayOfYear(dateTime);
        Date startTime = null;
        Date endTime = null;
        // 如果是 就查去年
        if(firstDayOfYear==true){
            // 查去年一整年的数据
            // 开始时间
            startTime = DateUtil.getFirstDayOfLastYear(dateTime);
            // 结束时间 当天时间0点
            endTime = DateUtil.getTodayTime(dateTime);

        }else {
            // 查今年一年的数据
            startTime = DateUtil.getFirstDayOfYear(dateTime);
            // 结束时间 当天时间0点
            endTime = DateUtil.getTodayTime(dateTime);

        }
        int staticType=4;

        //根据时间计算场站平均分并插入对应场站信息
        plantScoreService.getPlantAVGScore(startTime,endTime,staticType);

        //根据时间计算场站平均分并插入对应市级信息
        plantScoreService.getAreaAVGScore(startTime,endTime,staticType);

        //根据时间计算场站平均分并插入对应阳江信息
        plantScoreService.getYJAVGScore(startTime,endTime,staticType);
    }
}
